#include <iostream>
#include <future>
#include <thread>
#include <chrono>
#include <utility>

int func(int val) {
    std::this_thread::sleep_for(std::chrono::seconds(1));
    return val + 4;
}

int main() {
    std::packaged_task<int(int)> tsk(func);
    std::future<int> tsk_ret = tsk.get_future();
    std::thread(std::move(tsk), 5).detach();
    int ret = tsk_ret.get();
    std::cout << "ret: " << ret << std::endl;
    auto f1 = std::async(std::launch::async, [](){
    std::this_thread::sleep_for(std::chrono::seconds(2));return 3;});
    int ret2 = f1.get();
    std::cout << "ret2: " << ret2 << std::endl;

    return 0;
}